package com.lonty.intelligence.controller;

import com.lonty.intelligence.api.Result;
import com.lonty.intelligence.api.ResultCode;
import com.lonty.intelligence.service.CommunityService;
import com.lonty.intelligence.vo.CommunityVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author 陈璇
 * @Date 2020/4/16 13:45
 * @Version 1.0
 **/
@RestController
@RequestMapping("app/community")
@Validated
@Api(tags = "社区接口", produces = "application/json")
public class CommunityController {

    @Resource
    private CommunityService communityService;

    @ApiOperation(value = "保存社区", httpMethod = "POST")
    @PostMapping("saveCommunity")
    public Result saveCommunity(@ModelAttribute CommunityVo communityVo){
        if(communityService.saveCommunity(communityVo)){
            return Result.builder().build();
        }
        return Result.builder(ResultCode.OPERATION_ERROR).build();
    }

    @ApiOperation(value = "获取所有社区", httpMethod = "POST")
    @PostMapping("getCommunityList")
    public Result getCommunityList(){
        return Result.builder()
                .data(communityService.getCommunityList())
                .build();
    }

}
